<?php

/**
 * 通用控制器类
 * 
 * @package    01CMS
 * @subpackage admin
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

class CommonController extends Controller
{

    function __construct ()
    {
        parent::__construct();
    }

    /**
     * 验证码
     * 
     * @access 	public
     */
    function validateCode ()
    {
        lib('Session', FALSE);
        
        srand(microtime() * 100000);
        $string = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        $v1 = $string[strval(rand(0, 25))];
        $v2 = $string[strval(rand(0, 25))];
        $v3 = $string[strval(rand(0, 25))];
        $v4 = $string[strval(rand(0, 25))];
        $v5 = $string[strval(rand(0, 25))];
        $v6 = $string[strval(rand(0, 25))];
        Session::setCode('validateCode', $v1 . $v2 . $v3 . $v4 . $v5 . $v6, 900);
        $img = imagecreate(60, 20);
        imagecolorallocate($img, 0x66, 0x66, 0x66);
        $c[1] = imagecolorallocate($img, 0xff, 0xff, 0xff);
        $c[2] = imagecolorallocate($img, 0xee, 0xee, 0xee);
        $c[3] = imagecolorallocate($img, 0xbb, 0xbb, 0xbb);
        //imageline($img, 2, strval(rand("3", "16")), strval(rand("50", "57")), strval(rand("3", "16")), $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("1", "3")), strval(rand("0", "5")), $v1, $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("8", "12")), strval(rand("0", "5")), $v2, $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("18", "22")), strval(rand("0", "5")), $v3, $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("27", "33")), strval(rand("0", "5")), $v4, $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("37", "43")), strval(rand("0", "5")), $v5, $c[strval(rand("1", "3"))]);
        imagestring($img, 5, strval(rand("49", "50")), strval(rand("0", "5")), $v6, $c[strval(rand("1", "3"))]);
        header("content-type: image/png");
        imagepng($img);
        imagedestroy($img);
    }
}
